package com.dts.backproject.controller;


import com.dts.backproject.entity.po.Result;
import com.dts.backproject.entity.po.User;
import com.dts.backproject.service.UserService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据email查询用户信息
     * @param email
     * @return
     */
    @GetMapping
    public Result findByEmail(@RequestParam String email) {
        User user = userService.findByEmail(email);
        user.setPassword(null);
        return Result.success(user);
    }

    /**
     * 新增用户信息
     * @param user
     * @return
     */
    @PostMapping
    public Result saveUser(@RequestBody User user){
        userService.saveUser(user);
        return Result.success();
    }

    /**
     * 更新用户信息
     * @param user
     * @return
     */
    @PutMapping
    public Result updateByEamil(@RequestBody User user){
        userService.updateUser(user);
        return Result.success();
    }

    /**
     * 删除用户
     * @param email
     * @return
     */
    @DeleteMapping
    public Result deleteUser(@RequestParam String email){
        userService.deleteUser(email);
        return Result.success();
    }

    @PostMapping("/profile")
    public Result profile(@RequestBody User user){
        userService.profile(user);
        return Result.success();
    }
}
